﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.LIB;

namespace YArchitech.Controls.HeaderGridView
{
	public partial class FrmColumnSet : System.Windows.Forms.Form
	{
		public FrmColumnSet(DataGridView _dgv)
		{
			this.InitializeComponent();
			new HYProcessTools().ShowInTaskbarChange(this);
			this.dgv = _dgv;
		}

		private void frmColumnSet_Load(object sender, EventArgs e)
		{
			if (this.dgv == null)
			{
				return;
			}
			for (int i = 0; i < this.dgv.Columns.Count; i++)
			{
				for (int j = 0; j < this.dgv.Columns.Count; j++)
				{
					if (this.dgv.Columns[j].DisplayIndex == i)
					{
						DataGridViewColumn dataGridViewColumn = this.dgv.Columns[j];
						if (dataGridViewColumn.Tag == null || (int)dataGridViewColumn.Tag != 0)
						{
							TreeNode treeNode = new TreeNode(dataGridViewColumn.HeaderText);
							treeNode.Tag = dataGridViewColumn;
							treeNode.Checked = dataGridViewColumn.Visible;
							this.tv.Nodes.Add(treeNode);
						}
					}
				}
			}
		}

		private void btnAll_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.tv.Nodes.Count; i++)
			{
				this.tv.Nodes[i].Checked = true;
			}
		}

		private void btnClear_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.tv.Nodes.Count; i++)
			{
				this.tv.Nodes[i].Checked = false;
			}
		}

		private void btnReverse_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.tv.Nodes.Count; i++)
			{
				this.tv.Nodes[i].Checked = !this.tv.Nodes[i].Checked;
			}
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.tv.Nodes.Count; i++)
			{
				((DataGridViewColumn)this.tv.Nodes[i].Tag).Visible = this.tv.Nodes[i].Checked;
			}
			base.Close();
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private DataGridView dgv;
	}
}
